<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\agent\model;

class AgentList extends \app\BaseModel
{
    protected $name = "longbing_card_agent_list";
    protected $append = ["status_text", "have_count", "level_title"];
    public function getLevelTitleAttr($value, $data)
    {
        if(!empty($data["level"])) {
            $level_model = new AgentLevel();
            $dis[] = ["id", "=", $data["level"]];
            $dis[] = ["status", "=", 1];
            return $level_model->where($dis)->value("title");
        }
    }
    public function getStatusTextAttr($value, $data)
    {
        if(!empty($data["over_time"])) {
            switch ($data["over_time"]) {
                case time() < $data["over_time"]:
                    return "使用中";
                    break;
                case $data["over_time"] < time():
                    return "已过期";
                    break;
            }
        }
    }
    public function getHaveCountAttr($value, $data)
    {
        $num = \think\facade\Db::name("longbing_cardauth2_config")->where(["agent_id" => $data["id"]])->count();
        return $num;
    }
    public function agentList($dis, $page = 10)
    {
        $list = $this->where($dis)->order("id desc")->paginate($page)->toArray();
        return $list;
    }
    public function agentAdd($data)
    {
        $data["create_time"] = time();
        $data["update_time"] = time();
        $res = $this->insert($data);
        return $res;
    }
    public function agentUpdate($dis, $data)
    {
        $data["update_time"] = time();
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function agentInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
}

?>